const db = require("../config/db");
const mysql = require("mysql");
const pool = mysql.createPool(db);

module.exports = {
  /**
   * 从连接池中获取连接
   * @return {Promise<any>}
   */
  getConnection: function() {
    return new Promise((resolve, reject) => {
      pool.getConnection((error, connection) => {
        if (error) {
          reject({ message: `获取连接失败：${error.message}` });
          return;
        }
        resolve(connection);
      });
    });
  }
};
